<?php
session_start();

//  当前页面的URL
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
    $pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
    $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
} else {
    $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
$_SESSION['currentPageURL'] = $pageURL;

$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
$login_url = "https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=101213078" 
    . "&redirect_uri=" . urlencode('http://ibeginner.sinaapp.com/oauth2/qq/oauth/qq_callback.php')
    . "&state=" . $_SESSION['state']
    . "&scope=get_user_info";

?> 

<html lang="zh-cn">
    <head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>
            Demo for QQ登录oauth2.0
        </title>

    </head>
    <body>
        <font size=10><a href="http://wiki.opensns.qq.com/wiki/%E3%80%90QQ%E7%99%BB%E5%BD%95%E3%80%91Qzone_OAuth2.0%E7%AE%80%E4%BB%8B" target="_blank">新手教程</a></font>
        <p>请开发者修改comm/config.php文件中的$_SESSION["appid"]，$_SESSION["appkey"], $_SESSION["callback"]三个变量的值，以确保可以正常登录.</p>
        <br><br>
        <a href="#" onclick='toQzoneLogin()'><img src="img/qq_login.png"></a>
        <br><br>
        <a href="user/get_user_info.php"    target="_blank">获取用户信息</a>
		<br><br>
        <a href="share/add_share.html"      target="_blank">添加分享</a>
        <br><br>
        <a href="photo/list_album.php"      target="_blank">获取相册列表</a>
        <br><br>
        <a href="photo/add_album.html"      target="_blank">创建相册</a>
        <br><br>
        <a href="photo/upload_pic.html"     target="_blank">上传相片</a>
        <br><br>
        <a href="blog/add_blog.html"     target="_blank">发表日志</a>
        <br><br>
        <a href="topic/add_topic.html"     target="_blank">发表说说</a>
        <br><br>
        <a href="weibo/add_weibo.html"     target="_blank">发表微博</a>
        <br><br>
        <a href="<?=$login_url ?>">直接跳转</a>
        =========================
        <?=$_SESSION['currentPageURL']?>
    </body>
</html>


<?php 
    if ($_SESSION["QQUSERINFO"]) {
//        var_dump($_SESSION["QQUSERINFO"]);
        echo "======================".$_SESSION["QQUSERINFO"];
    }
?>